// import XtxSkeleton from './xtx-skeleton.vue'
// import XtxCarousel from './xtx-carousel.vue'
// import XtxMore from './xtx-more.vue'
// export default {
//   install (app) {
//     app.component(XtxSkeleton.name, XtxSkeleton)
//     app.component(XtxCarousel.name, XtxCarousel)
//     app.component(XtxMore.name, XtxMore)
//   }
// }

// import XtxSkeleton from './xtx-skeleton'
// import XtxCarousel from './xtx-carousel'
// import XtxMore from './xtx-more'
export default {
  install (app) {
    // 1. 加载components下所有的vue文件
    const ctx = require.context('./', false, /\.vue$/)
    // console.log(ctx)
    ctx.keys().forEach(item => {
      // item: 组件的地址  ctx(item) 导入这个组件
      const component = ctx(item).default
      app.component(component.name, component)
    })

    // 定义指令
    app.directive('lazy', {
      mounted (el, { value }) {
        const observer = new IntersectionObserver(([{ isIntersecting }], observer) => {
          if (isIntersecting) {
            observer.unobserve(el)
            el.src = value
            el.onerror = () => {
              el.src = require('@/assets/images/200.png')
            }
          }
        },
        {
          threshold: 0
        }
        )
        return observer.observe(el)
      }

    })
  }

}
